#include <windows.h>
#include "resource.h"
#include <stdio.h>

LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
char szAppName[] = "API"; // Class Name of the Windows, insignificant to users

// Declare the accelerator handler


int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow)
{
	HWND hwnd; // Declare the handle of your windows program
	MSG msg; // Declare the message container for message loop
	WNDCLASS wc; // Declare the structure of window class
	HACCEL hAccel;

	hAccel = LoadAccelerators(hInstance,"IDR_ACCE1");
	wc.style = CS_HREDRAW|CS_VREDRAW; // Redraw the windows after resizing
	wc.lpfnWndProc = WndProc; // Declare the callback procedure for the message handling
	wc.cbClsExtra = 0; // No extra memory for windows (mainly for resources)
	wc.cbWndExtra = 0;
	wc.hInstance= hInstance; // Declare the instance of current window
	wc.hIcon = LoadIcon(NULL,IDI_APPLICATION); // Load default icon
	wc.hCursor = LoadCursor(NULL,IDC_ARROW); // Load default cursor
	//wc.hbrBackground = (HBRUSH) GetStockObject(GRAY_BRUSH); // Set background to be white
	wc.hbrBackground = (HBRUSH)(WHITE_BRUSH+1); // Set background to be white
	//wc.lpszMenuName = NULL; // Do not load menu
	wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
	wc.lpszClassName = szAppName; // Declare the class name of the window class (unique for multiple class)

	// Registration of window class
	RegisterClass(&wc);

	// Create the window frame of your program
	hwnd = CreateWindow(szAppName,"( - __ - )y--~",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
		CW_USEDEFAULT,NULL,NULL,hInstance,NULL);

	// Show the frame of the window
	ShowWindow(hwnd,iCmdShow);

	// Refresh the client area
	UpdateWindow(hwnd);

	// Enter the message loop
	while (GetMessage(&msg,NULL,0,0))
	{
		if (!TranslateAccelerator(hwnd,hAccel,&msg))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}
	return msg.wParam;
	// End of message loop
}

LRESULT CALLBACK WndProc(HWND hwnd,UINT iMsg,WPARAM wParam,LPARAM lParam)
{

	HDC hdc; // Declare the device context
	PAINTSTRUCT ps; // Declare the painting structure for drawing
	LPSTR DBconnect_text = "DB Connect";
	LPSTR DBIPaddr_text = "DB Server IP";
	LPSTR DBPort_text = "DB Port";
	LPSTR DBStatus_text = "DB Status";
	LPSTR DBLoginUser_text = "DB Login User";
	LPSTR DBDefaultDB_text = "Default DB";
	LPSTR DBSetChar_text = "DB Set Char";


	// Enter the message handler loop
	switch (iMsg)
	{
		// Execute after CreateWindow()
	case WM_CREATE:
		return 0;

		// Execute after an invalidating regions appeared
	case WM_PAINT:
		hdc = BeginPaint(hwnd,&ps);
		SetTextColor(hdc, RGB(0,0,255));
		SetBkMode(hdc,TRANSPARENT);
		TextOut(hdc,10,10,DBconnect_text,strlen(DBconnect_text));
		TextOut(hdc,10,30,DBIPaddr_text,strlen(DBIPaddr_text));
		TextOut(hdc,10,50,DBPort_text,strlen(DBPort_text));
		TextOut(hdc,10,70,DBStatus_text,strlen(DBStatus_text));
		TextOut(hdc,10,90,DBLoginUser_text,strlen(DBLoginUser_text));
		TextOut(hdc,10,110,DBDefaultDB_text,strlen(DBDefaultDB_text));
		TextOut(hdc,10,130,DBSetChar_text,strlen(DBSetChar_text));
		EndPaint(hwnd,&ps);
		return 0;
	case WM_COMMAND:
		switch(LOWORD(wParam))
		{
		case ID_FILE_EXIT:
			PostQuitMessage(0);
			return 0;
		case ID_FILE_CONNECTDB:
			MessageBox(hwnd,
				TEXT("Connect DB"),TEXT("TEST"),MB_OK);
			return 0;
		case ID_FILE_DISCONNECTDB:
			MessageBox(hwnd,
			TEXT("Disconnect DB"),TEXT("TEST"),MB_OK);
			return 0;
		case ID_HELP_ABOUT:
			MessageBox(hwnd,
				TEXT("Version 1.0\nCopyright(C) By INhe"),
				TEXT("About"),MB_OK);
		};
	case WM_CHAR:
		InvalidateRect(hwnd,NULL,TRUE);
		return 0;
		// Execute when closing windows
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
	};

	// Execute if no message handler is mapped
	return DefWindowProc(hwnd,iMsg,wParam,lParam);
}
